//standardize assignee data
//format disambiguated firm data and merge back to full sample of raw data

insheet using "${rawdata}disambig_results.csv" , clear
drop if v1==""
rename v1 ee_name
rename v2 ee_name_disambig
drop if ee_name=="ee_name"
unique ee_name_disambig
bysort ee_name_disambig:gen count=_n
egen bus_tag=group(ee_name_disambig)
drop count
drop if ee_name==""
save "${filedata}disambig_firms_a", replace

use "${rawdata}assignment_data/assignment_conveyance.dta", clear
drop if employer_assign == 0
drop if convey_ty != "assignment"
merge 1:m rf_id using "${rawdata}assignment_data/documentid_admin.dta"
drop if convey_ty != "assignment"
drop if error != "none"
drop _merge
bysort rf_id: gen count = _N
bysort appno_doc_num: gen uniqueapp = _N
sort rf_id
joinby rf_id using "${rawdata}assignment_data/assignee.dta"
rename appno_doc_num application_number
keep application_number ee_name
recast str500 ee_name, force
merge m:1 ee_name using "${filedata}disambig_firms_a"
drop _merge
rename ee_name ee_name_raw
save "${filedata}disambig_firms_app", replace


